5.1 What is wrong with the following underlying method for calculating factorials?
/**
* Calculates the factorial of a non-negative integer, that is, the product of all
* integers between 1 and the given integer, inclusive. The worstTime(n) is O(n),
* where n is the given integer.
*
* @param n the non-negative integer whose factorial is calculated.
*
* @return the factorial of n
*
*/
public static long fact (int n)
{
if (n <= 1)
return 1;
return fact (n+1) / (n+1);
} // fact
 
 
View Solution
 
 
 
  Next >>